import TQRequest from "@/service/request";
import { BASE_URL, TIME_OUT } from "@/service/request/config";
import cache from "@/utils/cache";
const tqRequest = new TQRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: (config) => {
      // 携带token的拦截
      const token = cache.getCache("token");
      if (token) {
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        config.headers.Authorization = `Bearer ${token}`;
      }
      console.log("请求成功的拦截");
      return config;
    },
    requestInterceptorCatch: (err) => {
      console.log("请求失败的拦截");
      return err;
    },
    responseInterceptor: (res) => {
      console.log("响应成功的拦截", res.data);
      return res.data;
    },
    responseInterceptorCatch: (err) => {
      /*  console.log("响应失败的拦截");
      if (err.response.status === 404) {
        console.log("404错误");
      }*/
      console.log(err.response);
      return err;
    },
  },
});
export default tqRequest;
